/**
 * jims
 */
package com.jims.master.modules.csm.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.csm.dao.ExpInoutClassDao;
import com.jims.master.modules.csm.dao.ExpStorageDeptDao;
import com.jims.master.modules.csm.entity.ExpInoutClass;
import com.jims.master.modules.csm.entity.ExpStorageDept;
import com.jims.master.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service
 * @author DT
 * @version 2017-03-06
 */
@Service
@Transactional(readOnly = true)
public class ExpInoutClassService extends CrudService<ExpInoutClassDao, ExpInoutClass> {
	@Autowired
	private ExpStorageDeptDao expStorageDeptDao;
	public ExpInoutClass get(String id) {
		return super.get(id);
	}
	
	public List<ExpInoutClass> findList(ExpInoutClass expInoutClass) {
		return super.findList(expInoutClass);
	}
	
	public Page<ExpInoutClass> findPage(Page<ExpInoutClass> page, ExpInoutClass expInoutClass) {
		return super.findPage(page, expInoutClass);
	}
	
	@Transactional(readOnly = false)
	public int save(ExpInoutClass expInoutClass) {
		return super.save(expInoutClass);
	}
	
	@Transactional(readOnly = false)
	public int delete(ExpInoutClass expInoutClass) {
		return super.delete(expInoutClass);
	}

	@Transactional(readOnly = false)
	public List<String> findByLevel(String inOutFlag){
		String storageLevel="";
		/**update by CTQ AT 2017-07-10 16:26:49 如果值为空，则不让取值**/
		String deptId= UserUtils.getUser().getOrgDept()!=null?UserUtils.getUser().getOrgDept().getId():"";
		if(StringUtils.isNotBlank(deptId)){
			ExpStorageDept esd = expStorageDeptDao.get(deptId);
			if(esd!=null){
				storageLevel = esd.getStorageLevel();
			}
			return dao.findByLevel(storageLevel,inOutFlag);
		}
		else{
			return dao.findByLevel("",inOutFlag);
		}
	}
}